package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.LoanService;
import util.ServiceFactory;

import com.heantai.easystruts.controller.Action;

public class ApplyLoanAction extends Action {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		LoanService service = ServiceFactory.getInstance(LoanService.class);
		String account=request.getParameter("account");
		double amount=Double.parseDouble(request.getParameter("amount"));
		double rs=service.apply(account, amount);
		if(rs==-1){
			request.setAttribute("result", "account not exist");
			return "fail";
		}else if(rs==-2){
			request.setAttribute("result", "贷款金额超过额度");
			return "fail";
		}else{
			request.setAttribute("result", "申请通过,可以贷款的金额为:"+amount);
			return "success";
		}
	}

}
